<?php

    require '/var/www/pdd/wxpay11/lib/WxPay.Api.php';
    ini_set('date.timezone','Asia/Shanghai');
//    include './wxpay11/lib/WxPay.Api.php';
    $wxpay = new WxPayApi();
    $input = new WxPayRefundQuery();
    $dbms='mysql';     //数据库类型
    $host='127.0.0.1'; //数据库主机名
    $dbName='pdd';     //使用的数据库
    $user='root';      //数据库连接用户名
    $pass='XiaoL511';  //对应的密码
    $dsn="$dbms:host=$host;dbname=$dbName";
    try {
        $dbh = new PDO($dsn, $user, $pass); //初始化一个PDO对象
        $list = $dbh->query('SELECT id,number from refund where state <= 2 ');
        foreach ($list as $row) {
            $input->SetOut_trade_no($row['number']);
            $info = $wxpay->refundQuery($input);
            if ($info['refund_status_0'] == 'SUCCESS')
                $dbh->query('UPDATE refund SET state = 3 WHERE id ='.$row['id']);
        }
        $dbh = null;
    } catch (PDOException $e) {
        die ("Error!: " . $e->getMessage() . "<br/>");
    }



